<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 得到目标值的最少行动次数 -->
    <script>
      var minMoves = function (target, maxDoubles) {
        let count = 0
        while (target > 1 && maxDoubles && ++count) {
          if (target % 2 === 0) maxDoubles--, (target /= 2)
          else target -= 1
        }
        return count + target - 1
      }
      console.log(minMoves(5, 0))
    </script>
  </body>
</html>
